<template>
<div>
  <el-button type="primary" @click="findByCondtion">主要按钮</el-button>
  <el-table :data="tableData">
    <el-table-column prop="author" label="作者" width="140">
    </el-table-column>
    <el-table-column prop="name" label="姓名" width="120">
    </el-table-column>
    <el-table-column prop="publisher" label="出版社">
    </el-table-column>

    <el-table-column prop="stock" label="库存">
    </el-table-column>
  </el-table>
  <el-pagination
      :page-size="pageSize"
      :pager-count="pageNum"
      :total="totalCount"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      layout="total, sizes, prev, pager, next, jumper">

  </el-pagination>
</div>
</template>

<script>
import request from "@/utils/request";

export default {
  data() {
    return {
      pageSize: 2,
      pageNum: 1,
      totalCount: 0,
      tableData: []
    }
  },
  mounted() {
    this.findAll()
  },
  methods: {
    findAll() {
      // request({
      //   url: "/goods/findByPage",
      //   method: "post"
      // }).then(res => {
      //   console.log(res)
      // })
      const findAllRequest = {
        userId: this.pageSize,
        pageNum: this.pageNum
      }
      request.post("/goods/findByPage",findAllRequest)
      .then(res=>{
        console.log(res.data)
        this.tableData = res.data.data.list
        this.totalCount=res.data.data.totalCount
        // console.log(res.data)
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.pageNum = 1;
      this.findAll()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.findAll()
    },

  }
};
</script>
